package com.leo.entity;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.EntityFactory;
import com.almasb.fxgl.entity.SpawnData;
import com.almasb.fxgl.entity.Spawns;
import com.almasb.fxgl.entity.components.IDComponent;
import com.almasb.fxgl.texture.Texture;
import com.leo.common.FruitType;
import com.leo.component.FruitComponent;

import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: wangss
 * @CreateTime: 2023-06-18  06:28
 * @Description: TODO
 */
public class FruitEntityFactory implements EntityFactory {

    private AtomicInteger index = new AtomicInteger(0);

    // 注意spawns逗号不能有空格
    @Spawns("apple,orange,lime,blueberry,strawberry")
    public Entity createFruit(SpawnData spawnData) {
        FruitType type = spawnData.get("type");
        Texture texture = FXGL.texture(type.toString().toLowerCase(Locale.ROOT) + ".png", 50, 50);
        return FXGL.entityBuilder(spawnData)
                .type(type)
                .viewWithBBox(texture)
                .with(new FruitComponent())
                .with(new IDComponent(type.toString().toLowerCase(Locale.ROOT), index.getAndIncrement()))
                .build();
    }
}
